#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

typedef struct {
    char date[20];
    float temp_high;
    float temp_low;
    char weather_day[20];
    char weather_night[20];
} WeatherData;

void process_csv(const char* filename, WeatherData** data, int* count) {
    FILE* file = fopen(filename, "r");
    if (!file) {
        perror("文件打开失败");
        exit(EXIT_FAILURE);
    }

    // 跳过标题行
    char buffer[256];
    fgets(buffer, sizeof(buffer), file);
    
    // 统计行数
    *count = 0;
    while (fgets(buffer, sizeof(buffer), file) (*count)++;
    rewind(file);
    fgets(buffer, sizeof(buffer), file);  // 再次跳过标题行

    // 分配内存
    *data = (WeatherData*)malloc(*count * sizeof(WeatherData));
    
    // 解析数据
    for (int i = 0; i < *count; i++) {
        fgets(buffer, sizeof(buffer), file);
        sscanf(buffer, "%[^,],%f,%f,%[^,],%[^,\n]",
               (*data)[i].date, &(*data)[i].temp_high, &(*data)[i].temp_low,
               (*data)[i].weather_day, (*data)[i].weather_night);
    }
    fclose(file);
}